<?php
// 意见反馈页面
include("common.inc.php");
InitGP(array("action","msg","page","gid")); //初始化变量全局返回

include(INC_PATH."/guestbook.class.php");
$gb=new GuestBook();
//初始化对象
include(INC_PATH."/group.class.php"); //包含团购类
$gp=new GroupClass();

//处理留言入库
if ($action=="ajax" && !empty($msg)) {
	AjaxHead();
	if (!empty($_USERS)) {
		$msg=iconv('utf-8', CHARSET, js_unescape($msg));
		
		$info=$gb->add($msg,$_USERS['uid'],$_USERS['uname']);
		if ($info=="OK") {
			$retunstr="OK";
		}else {
			$retunstr=$info;
		}
		
	}else $retunstr="用户未登录";
	echo iconv(CHARSET, 'UTF-8',$retunstr); 
	exit;
}

//判断后台是否设置首页显示团购ID
if(GetNum($gid)){
	$gid=GetNum($gid);
}else {
	//自动显示当天ID团购
	$todaystart=strtotime(date('Y-m-d 0:0:0',time()));
	$todayend=strtotime(date('Y-m-d 0:0:0',time()+3600*24));
	$wheresql="group_begin_time >{$todaystart} and group_begin_time < {$todayend}";
	//$wheresql="TO_DAYS(group_begin_time) = TO_DAYS(NOW())";
	$returnarray = $gp->getdata(1,"",$wheresql);
	//print_r($returnarray);
	$gid=$returnarray[0]['gid'];//设置查询到的gid
	unset($returnarray);	//清空数组
	
}
$value=$gp->getone($gid); 	//获取团购信息

$wherestr[]="state = 1";
if(!empty($wherestr)) $wheresql = implode(' AND ', $wherestr);	//条件汇总

//获取当前页码
$total=$gb->getcount($wheresql); 							  //总信息数
$pagesize=15;												  //一页显示信息数
$page = isset($page) ? max(1, intval($page)) : 1;             //处理页码变量
$offset=($page-1)*$pagesize;   								  //偏移量
$dataarray=$gb->getdata("$offset,$pagesize",$wheresql); //获取团购数据



	include(INC_PATH."/article.class.php");
	$art=new ArticleClass();
	
	$datagg=$art->getdata('','typeid=3');

/*
print_r($dataarray);
print_r($value);
*/
//对js的escape 进行反编码用
function js_unescape($str)
{
        $ret = '';
        $len = strlen($str);

        for ($i = 0; $i < $len; $i++)
        {
                if ($str[$i] == '%' && $str[$i+1] == 'u')
                {
                        $val = hexdec(substr($str, $i+2, 4));

                        if ($val < 0x7f) $ret .= chr($val);
                        else if($val < 0x800) $ret .= chr(0xc0|($val>>6)).chr(0x80|($val&0x3f));
                        else $ret .= chr(0xe0|($val>>12)).chr(0x80|(($val>>6)&0x3f)).chr(0x80|($val&0x3f));

                        $i += 5;
                }
                else if ($str[$i] == '%')
                {
                        $ret .= urldecode(substr($str, $i, 3));
                        $i += 2;
                }
                else $ret .= $str[$i];
        }
        return $ret;
}


include template('guestbook');//包含输出指定模板
?>